package com.mentalhealthplatform.global.rbac.repository;

import com.mentalhealthplatform.global.rbac.model.Endpoint;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;
import java.util.Set;

@Repository
public interface EndpointRepository extends JpaRepository<Endpoint, Long> {

    Optional<Endpoint> findByPathAndMethod(String path, String method);

    Optional<Endpoint> findByIdentifier(String identifier);

    boolean existsByPath(String path);

    @Query("SELECT e FROM Endpoint e WHERE e.identifier LIKE %:search% OR e.path LIKE %:search%")
    Page<Endpoint> findByIdentifierContainingOrPathContaining(@Param("search") String search, Pageable pageable);

    Set<Endpoint> findByIdIn(Set<Long> ids);

    boolean existsByIdentifier(String identifier);
}
